<template>
	<view class="page">
			<view class="searchBox"  >
				<view class="inputBox">
					<view class="inputRow" @click="workDateShow=true">
						<view class="label">
							{{language.planWorkList.label1}}:
						</view>
						<view :class="params.workDate ? 'val' : 'emty'" @click="workDateShow=true">
							{{params.workDate ? params.workDate : language.auditRepairList.tip1 }}
						</view>
					</view>
					<view class="inputRow" v-if="isAll==1">
						<view class="label">
							{{language.planWorkList.label2}}:
						</view>
						<view class="val">
							<u-input v-model="params.personName" :placeholder="language.planWorkList.tip1"></u-input>
						</view>
					</view>
				</view>
				<view class="btnBox">
					<view class="btn"  @click="goSearch">
						{{language.auditRepairList.search}}
					</view>
				</view>
			</view>
			<scrollYBox styleText="height: calc( 100vh - 210rpx ) ;" @scrolltolower="scrolltolower" :list="list">
						<template>
							<view style="padding-bottom: 50rpx;">
								<view class="boxItem" v-for="(item,index) in list" :key="index">
									<view class="row flex">
										<view class="item ">
											<view class="label">
												{{language.planWorkList.label3}}
											</view>
											<view class="val">
												{{item.departmentId_dictText}}
											</view>
										</view>
										<view class="item ">
											<view class="label">
												{{language.planWorkList.label4}}
											</view>
											<view class="val">
												{{item.personGroupId_dictText}}
											</view>
										</view>
										
									</view>
									<view class="row flex">
										<view class="item ">
											<view class="label">
												{{language.planWorkList.label2}}
											</view>
											<view class="val">
												{{item.personId_dictText}}
											</view>
										</view>
										<view class="item " style="">
											<view class="label">
												{{language.planWorkList.label1}}
											</view>
											<view class="val">
												{{item.workDate}}
											</view>
										</view>
										
									</view>
									<view class="row flex">
										<view class="item">
											<view class="label">
												{{language.planWorkList.label5}}
											</view>
											<view class="val">
												{{item.timePeriodIdDetail}}
											</view>
										</view>
									</view>
								</view>
							</view>
						</template>
					</scrollYBox>
				<u-modal :show="auditShow"  title="审核" showConfirmButton showCancelButton @cancel="auditShow=false" @confirm="auditConfirm" >
					<view class="slot-content">
						<view class="" style="width: 600rpx;">
							<u-radio-group
							   v-model="auditValue"
							   placement="row"
							 >
							   <u-radio
							     :customStyle="{marginRight: '8px'}"
							     v-for="(item, index) in auditList"
							     :key="index"
							     :label="item.name"
							     :name="item.value"
							   >
							   </u-radio>
							 </u-radio-group>
							 <view class="" style="border: 1px solid #eaeaea;margin-top: 20rpx;">
								<u--textarea v-model="auditOpinion" :placeholder="language.planWorkList.tip1" ></u--textarea>
							 </view>
						</view>
						
					</view>
				</u-modal>
		<u-datetime-picker
		    :show="workDateShow" ref="datetimePicker" v-model="workDate" 
		    mode="date"  @cancel="workDateShow=false" @confirm="workDateConfirm"
		       ></u-datetime-picker>
		<u-datetime-picker
			:show="createTime_endShow" ref="datetimePicker" v-model="createTime_end" 
			mode="date"  @cancel="createTime_endShow=false" @confirm="createTime_endConfirm"
		   ></u-datetime-picker>
	</view>
</template>

<script>
	import {attScheduleListApi,} from '@/common/api/commonApi/checking.js'
	export default {
		data() {
			return {
				list:[],
				params:{
					workDate : '',
					personName:'',
					pageNo:1,
					pageSize: 10,
				},
				workDate: Number(new Date()),
				createTime_end: Number(new Date()),
				workDateShow : false,
				createTime_endShow : false,
				total : 0,
				auditObj:{},
				auditShow: false,
				auditList: [{
						name: '通过',
						value: 1
					},
					{
						name: '未通过',
						value: 2,
					},
				],
				auditValue: 1,
				auditOpinion:'',
				selectList:[
					'待审核',
					'通过',
					'未通过',
				],
				current:0,
				isAll: 1,
				selectInfoAccount: uni.getStorageSync('selectInfoAccount'),
			}
		},
		components:{
		},
		methods: {
			workDateConfirm(e){
				let date = this.dateformat(e.value).split(' ')[0]
				this.params.workDate = date
				console.log(this.params.workDate);
				this.workDateShow = false
			},
			createTime_endConfirm(e){
				let date = this.dateformat(e.value).split(' ')[0]
				this.params.createTime_end = date
				this.createTime_endShow = false
			},
			sectionChange(index){
				this.current = index
				this.getList()
			},
			auditConfirm(){
				let data = this.auditObj
				data.status = this.auditValue
				data.resultRemark = this.auditOpinion
				// data.applyResultId
				// data.reviewid = uni.getStorageSync('selectInfoAccount').id
				console.log(data);
				attScheduleSwaprecAuditApi(data).then(res=>{
					this.getList().then(res=>{
						this.setMessage('审核成功')			
					})
				}).finally(res=>{
					this.auditShow = false
				})
			},
			handleAudits(item){
				this.auditObj = item
				this.auditShow = true
				
			},
			handleCancel(item){
				uni.showModal({
				    title: '提示',
				    content: '确定要取消请假吗？',
				    success: (res)=> {
				        if (res.confirm) {
				            console.log('用户点击确定')
				            // that.cancel(item)
							item.delflag = 1
							attAskforleaveEditApi(item).then(res=>{
								this.getList().then(res=>{
									this.setMessage('取消成功')				   
								})
							})
				        } else if (res.cancel) {
				            console.log('用户点击取消')
				        }
				    }
				})
			},
			handleRemove(item){
				uni.showModal({
				    title: '提示',
				    content: '确定要销假吗？',
				    success: (res)=> {
				        if (res.confirm) {
							item.isResumption = 1
							attAskforleaveAuditsApi(item).then(res=>{
								this.getList().then(res=>{
									this.setMessage('销假成功')				   
								})
							})
				        } else if (res.cancel) {
				            console.log('用户点击取消')
				        }
				    }
				})
			},
			handleEdit(item){
				this.goPage('/pages/componentsC/checkingIn/leaveRequest',{
					item:JSON.stringify(item),
					isAdd:2,
				})
			},
			handleDetail(item){
				this.goPage('/pages/componentsC/checkingIn/leaveRequest',{
					item:JSON.stringify(item),
					isAdd:3,
				})
			},
			scrolltolower(){
				if(this.total == this.list.length){
					return this.setMessage('没有更多了')
				}
				this.params.pageNo ++
				this.getList()
			},
			goSearch(){
				if(this.params.workDate && this.params.createTime_end ){
					if(new Date(this.params.workDate) > new Date(this.params.createTime_end) ) return this.setMessage('开始时间不能大于结束时间')
				}
				this.params.pageNo = 1 
				this.getList()
			},
			getList(){
				let params = this.params
				if(this.isAll==2){
					params.personId = this.selectInfoAccount.id
				}
				// else{
				// params.status = this.current
					// if(this.current==0){
					// }else if(this.current==1){
					// 	params.status = 2
					// }
				// }
				return attScheduleListApi(params).then(res=>{
					if(params.pageNo==1) this.list = []
					this.list = this.list.concat(res.result.records)
					this.total = res.result.total
				})
			},
			goSearch(){
				this.params.pageNo = 1
				this.getList()
			}
			
		},
		onLoad({isAll}) {
			if(isAll) this.isAll = isAll
			this.setPageTitle(this.language.planWorkList.title)
			this.getList()
		},
		onShow() {
		},
	}
</script>

<style lang="scss" scoped>
	.searchRow{
			background-color: #fff;
			display: flex;
			align-items: center;
			padding: 0rpx 20rpx 0 20rpx;
			border-bottom: 2rpx solid #dedede;
			height: 140rpx;
			margin: 20rpx;
			.leftBox{
				flex: 1;
				.row{
					display: flex;
					align-items: center;
					height: 70rpx;
					padding-left: 20rpx;
					.label{
						color: #000000d9;
						margin-right: 30rpx;
					}
					.val{
						color: #595959;
					}
				}
			}
			.btn{
				width: 140rpx;
				height: 56rpx;
				border-radius: 10rpx;
				color: #fff;
				@include flexCenter;
				background-color: #4089f0;
			}
			
	}
	
	
.page{
	background-color: #f1f1f1;
	// height: 100vh;
	.searchBox{
		display: flex;
		align-items: center;
		background-color: #fff;
		padding: 0 20rpx;
		border-bottom: 1px solid #f1f1f1;
		margin: 20rpx;
		border-radius: 8rpx;
		box-shadow: 0px 6rpx 12rpx rgba(0, 0, 0, 0.16);
		.inputBox{
			flex: 1;
			padding-right: 30rpx;
			.inputRow{
				height: 80rpx;
				display: flex;
				align-items: center;
				font-size: 32rpx;
				padding-left: 20rpx;
				.label{
					color: #191919;
					margin-right: 30rpx;
				}
			}
			.input{
				
			}
			.emty{
				color: #c0c4cc;
			}
			.val{
				
			}
		}
		.btnBox{
			display: flex;
			flex-direction: column;
			padding: 10rpx 0;
			.reset{
				margin-top: 20rpx;
				border: 1px solid #f1f1f1;
				background: #fff !important;
				color: #353535 !important;
			}
			.btn{
				padding: 0 30rpx;
				// width: 110rpx;
				height: 60rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				background: #1890ff;
				border-radius: 8rpx;
				color: #fff;
			}
		}
	}
	
	.boxItem{
			background-color: #fff;
			margin: 20rpx;
			border-radius: 8rpx;
			padding: 10rpx;
			box-shadow: 0px 0px 20rpx 0px rgba(102,102,102,0.15);
			.row{
				margin: 10rpx;
				display: flex;
				.item{
					// padding-left: 10rpx;
					// width: 50%;
					flex: 1;
				}
				.label{
					color: #969696;
				}
				.val{
					color: #353535;
					font-size: 32rpx;
					 // white-space: pre-wrap;
					 padding: 0 10rpx;
					 // width: 380rpx;
					 // width: 50%;
					text{
						white-space: nowrap;
					}
				}
				.btn{
						padding: 0 30rpx;
						// width: 120rpx;
						height: 60rpx;
						display: flex;
						align-items: center;
						justify-content: center;
						background: #1890ff;
						border-radius: 8rpx;
						color: #fff;
						margin-right: 10rpx;
				}
			}
		}
		
}
</style>
